package com.lgx.mall.core.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import net.sf.json.JSONObject;

import com.lgx.common.entity.IdGenerator;

/**
 * 商品类型分类
 * 
 * @author hezhuo
 *
 */
@Entity
@Table(name = "TM_CATEGORY")
public class Category implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7814068971399997851L;

	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator=IdGenerator.TM_CATEGORY_ID)
	@TableGenerator(
			name = IdGenerator.TM_CATEGORY_ID,
			table = IdGenerator.GENERATOR_TABLE,
			pkColumnName = IdGenerator.GEN_NAME,
			pkColumnValue = IdGenerator.TM_CATEGORY_ID,
			valueColumnName = IdGenerator.GEN_VALUE,
			initialValue = 1,
			allocationSize = 1
	)
	private long id;
	
	/**
	 * 类名(餐饮、日用）
	 */
	private String name;
	
	/**
	 * 类名描述
	 */
	private String description;
	
	private String url;
	
	@ManyToOne
	@JoinColumn(name = "parent")
	private Category parent;
	
	@Transient
	private List<Category> children = new ArrayList<Category>();
	
	private String layerOrder;
	
	/**
	 * 是否发送购物信息
	 */
	private String sendMsg;
	
	private int pcount;

	public int getPcount() {
		return pcount;
	}

	public void setPcount(int pcount) {
		this.pcount = pcount;
	}

	public String getSendMsg() {
		return sendMsg;
	}

	public void setSendMsg(String sendMsg) {
		this.sendMsg = sendMsg;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Category getParent() {
		return parent;
	}

	public List<Category> getChildren() {
		return children;
	}

	public void setChildren(List<Category> children) {
		this.children = children;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}

	public String getLayerOrder() {
		return layerOrder;
	}

	public void setLayerOrder(String layerOrder) {
		this.layerOrder = layerOrder;
	}
	
	@Override
	public String toString() {
		JSONObject obj = new JSONObject();
		
		obj.put("id", this.getId());
		obj.put("name", this.getName());
		obj.put("description", this.getDescription());
		obj.put("url", this.getUrl());
		obj.put("sendMsg", this.getSendMsg());
		obj.put("pcount", this.getPcount());
		
		return obj.toString();
	}
}
